package com.rzy.a_thread.c;

import java.io.IOException;

/**
 * @author gao
 * @time 2020/05/28 00:20:43
 */

/*
使用interrupted停止一个线程
 */
class A implements Runnable {
    @Override
    public void run() {
        while (!Thread.interrupted()) {
            System.out.println("用筷子夹面");
            System.out.println("吸溜到一半，一半面在嘴外面");
            System.out.println("吸溜完");
            System.out.println("咀嚼");
            System.out.println("下咽");
        }
        System.out.println(Thread.interrupted());
    }
}

public class App {
    public static void main(String[] args) throws IOException {
        A a = new A();
        Thread th = new Thread(a);
        th.start();

        System.out.println("Enter...");
        System.in.read();

        // 给线程发送一个interrupt信号
        th.interrupt();

    }

}
